package com.JiaLiang.ssm.service.Impl;

import com.JiaLiang.ssm.mapper.UserMapper;
import com.JiaLiang.ssm.pojo.User;
import com.JiaLiang.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private  UserMapper userMapper;

    /*@Autowired
    @Qualifier("userService")
    public void setUserMapper(UserMapper userMapper){
        UserServiceImpl.userMapper = userMapper;
    }*/

    @Override
    public User Login(String username, String password) {
        User user = userMapper.selectByUsername(username);
        if(user.getUsername().equals(username) && user!=null){
            return user;
        }
        return null;
    }

    @Override
    public Boolean Register(User user) {
        int count = userMapper.insertUser(user);
        if(count==1){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Boolean usernameExist(String username) {
        if (userMapper.selectByUsername(username)!=null){
            return true;
        }else {
            return false;
        }
    }


}
